{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "778aa8f9",
   "metadata": {},
   "source": [
    "## 上周回顾（range（））：range：范围\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8878c0a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# start?stop?step?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "774d5a34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c115de5b",
   "metadata": {},
   "source": [
    "### 课后练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "26980066",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2b642a04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9e362894",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 12, 4)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,12,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c406fcc1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "5\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,12,4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "551ebb68",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'start' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# start:开头 开始  stop：停止  step：步\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28mrange\u001b[39m(\u001b[43mstart\u001b[49m,stop,step)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'start' is not defined"
     ]
    }
   ],
   "source": [
    "# start:开头 开始  stop：停止  step：步\n",
    "range(start,stop,step)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ff2ec0c",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type():检查类型\n",
    "\n",
    "> 1. 数值\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex\n",
    "> 2. 字符串\n",
    ">> 1. 字符串的定义\n",
    ">> 2. 字符串的拼接\n",
    ">>> 1. 字符串不可以和数字连接\n",
    ">>> 2. 字符串不可以用来运算\n",
    ">> 3. 字符串方法\n",
    ">>> 1. capitalize(): 可以将字母转化为大写\n",
    ">>> 2. count(): 数量 （）里面写要查找的内容\n",
    ">>> 3. split()\n",
    ">> 4. in 检查成员对象\n",
    ">> 5. len() 检查文本总长度\n",
    ">> 6. enumerate:枚举，即可以获取内容，又可以获取索引值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2dce700c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## Number(数值)\n",
    "\n",
    "a = 9\n",
    "print(a,type(a))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "916501bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float\n",
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e8e4d99f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数，复数)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "939eca37",
   "metadata": {},
   "source": [
    "## 字符串（string）\n",
    "> 1. 关于字符串的基本内容\n",
    "> 2. 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "69b8f43b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fdd18471",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ba140530",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = '''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "64a33ea2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c23f8056",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'nfdsjkf\"fdsnjlk'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'nfdsjkf\"fdsnjlk'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1216d42e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "fda01b60",
   "metadata": {},
   "outputs": [],
   "source": [
    "nfu_index_pages_html=\"\"\"\n",
    "<meta name=\"renderer\" content=\"webkit\">\n",
    "\t<!-- 强制360默认使用极速模式 -->\n",
    "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n",
    "\t<!-- 强制360默认使用极速模式 -->\n",
    "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n",
    "\t<title>广州南方学院</title>\n",
    "\t<meta name=”keywords” content=”南方学院,广州南方,本科,一流大学″>\n",
    "       <meta name=”description” content=”广州南方学院”>\n",
    "\n",
    "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/swiper-3.3.1.min.css\">\n",
    "\t<link href=\"css/lin.css\" rel=\"stylesheet\" type=\"text/css\">\n",
    "\n",
    "\t<script src=\"js/jquery-1.11.3.min.js\">\n",
    "\t</script>\n",
    "\t<script src=\"js/jquery-1.11.1.js\">\n",
    "\t</script>\n",
    "\t<script src=\"js/jquery.easie-min.js\" type=\"text/javascript\">\n",
    "\t</script>\n",
    "\t<script src=\"js/swiper.min.js\" type=\"text/javascript\">\n",
    "\t</script>\n",
    "\t<script src=\"js/lin.js\">\n",
    "\t</script>\n",
    "\t\n",
    "\t\n",
    "\t<link href=\"css/page.css\" rel=\"stylesheet\" type=\"text/css\">\n",
    "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Shortcut Icon\">\n",
    "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Bookmark\">\n",
    "\n",
    "\t<link rel=\"stylesheet\" href=\"css/jalendar.css\" type=\"text/css\">\n",
    "\t<script src=\"js/jquery.SuperSlide.2.1.js\" type=\"text/javascript\">\n",
    "\t</script>\n",
    "\t<script type=\"text/javascript\" src=\"js/jalendar.js\">\n",
    "\t</script>\n",
    "\t<!--<script type=\"text/javascript\">\n",
    "\t\tvar w=window.screen.width;\n",
    "\t\tif(w<=640){\n",
    "\t\t\tlocation.href=\"https://www.nfu.edu.cn/index.htm\";\n",
    "\t\t}\n",
    "\t\t$(function () {\n",
    "\t\t\t$('#myId').jalendar({\n",
    "\t\t\t\tcustomDay: '2020/4/07',\n",
    "\t\t\t\tcolor: '#ed145a',\n",
    "\t\t\t\tlang: 'EN'\n",
    "\t\t\t});\n",
    "\t\t});\n",
    "\t</script>-->\n",
    "\t<link rel=\"stylesheet\" href=\"css/orman.css\" type=\"text/css\" media=\"screen\">\n",
    "\t<link rel=\"stylesheet\" href=\"css/nivo-slider.css\" type=\"text/css\" media=\"screen\">\n",
    "\n",
    "\n",
    "\t﻿<!--头部-->\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "af9129ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<meta name=\"renderer\" content=\"webkit\">\n",
      "\t<!-- 强制360默认使用极速模式 -->\n",
      "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n",
      "\t<!-- 强制360默认使用极速模式 -->\n",
      "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n",
      "\t<title>广州南方学院</title>\n",
      "\t<meta name=”keywords” content=”南方学院,广州南方,本科,一流大学″>\n",
      "       <meta name=”description” content=”广州南方学院”>\n",
      "\n",
      "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/swiper-3.3.1.min.css\">\n",
      "\t<link href=\"css/lin.css\" rel=\"stylesheet\" type=\"text/css\">\n",
      "\n",
      "\t<script src=\"js/jquery-1.11.3.min.js\">\n",
      "\t</script>\n",
      "\t<script src=\"js/jquery-1.11.1.js\">\n",
      "\t</script>\n",
      "\t<script src=\"js/jquery.easie-min.js\" type=\"text/javascript\">\n",
      "\t</script>\n",
      "\t<script src=\"js/swiper.min.js\" type=\"text/javascript\">\n",
      "\t</script>\n",
      "\t<script src=\"js/lin.js\">\n",
      "\t</script>\n",
      "\t\n",
      "\t\n",
      "\t<link href=\"css/page.css\" rel=\"stylesheet\" type=\"text/css\">\n",
      "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Shortcut Icon\">\n",
      "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Bookmark\">\n",
      "\n",
      "\t<link rel=\"stylesheet\" href=\"css/jalendar.css\" type=\"text/css\">\n",
      "\t<script src=\"js/jquery.SuperSlide.2.1.js\" type=\"text/javascript\">\n",
      "\t</script>\n",
      "\t<script type=\"text/javascript\" src=\"js/jalendar.js\">\n",
      "\t</script>\n",
      "\t<!--<script type=\"text/javascript\">\n",
      "\t\tvar w=window.screen.width;\n",
      "\t\tif(w<=640){\n",
      "\t\t\tlocation.href=\"https://www.nfu.edu.cn/index.htm\";\n",
      "\t\t}\n",
      "\t\t$(function () {\n",
      "\t\t\t$('#myId').jalendar({\n",
      "\t\t\t\tcustomDay: '2020/4/07',\n",
      "\t\t\t\tcolor: '#ed145a',\n",
      "\t\t\t\tlang: 'EN'\n",
      "\t\t\t});\n",
      "\t\t});\n",
      "\t</script>-->\n",
      "\t<link rel=\"stylesheet\" href=\"css/orman.css\" type=\"text/css\" media=\"screen\">\n",
      "\t<link rel=\"stylesheet\" href=\"css/nivo-slider.css\" type=\"text/css\" media=\"screen\">\n",
      "\n",
      "\n",
      "\t﻿<!--头部-->\n"
     ]
    }
   ],
   "source": [
    "print(nfu_index_pages_html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac7209a5",
   "metadata": {},
   "source": [
    "### 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cbef57d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "title = \"curry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b63be878",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "curry <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(title,type(title))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f266cc3",
   "metadata": {},
   "source": [
    "# 2.关于字符串的方法及函数\n",
    "> 1. 字符串的定义\n",
    ">> 1. Single quotes: 'allows embedded \"double\" quotes'\n",
    ">> 2. Double quotes: \"allows embedded 'single' quotes\"\n",
    ">> 3. Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n",
    "> 2. in 检查成员对象\n",
    "> 3. 字符串的拼接\n",
    "> 4. 字符串的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "4c549851",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考 如何判断一段文本中是否存在\"广州”，例如 文本 title中的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "ebdc1732",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化区温泉镇\n"
     ]
    }
   ],
   "source": [
    "title = \"广州南方学院坐落于广州市从化区温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "075f94b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e7b412ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查文本的总长度\n",
    "len(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ae7f1dde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "15a2402b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'泉'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "805ecd4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取一定范围的值，这种方法我们称其为“切片”\n",
    "title[0:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "84f55827",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4bacb58e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'于广州市从化区温泉镇'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[8:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5509267a",
   "metadata": {},
   "source": [
    "## enumerate 枚举，既可以获取到内容 item ，又可以获取到  索引值 index。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c3303f1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 区\n",
      "15 温\n",
      "16 泉\n",
      "17 镇\n"
     ]
    }
   ],
   "source": [
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "73172b32",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本  title  中的内容,还可以确定其出现的次数 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "65c93a17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "广州这个词在这段文字中\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "广州这个词在这段文字中\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 区\n",
      "15 温\n",
      "16 泉\n",
      "17 镇\n"
     ]
    }
   ],
   "source": [
    "# 方法1\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)\n",
    "    if j == \"广\":\n",
    "         if title[i+1] == \"州\":\n",
    "                print(\"广州这个词在这段文字中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "9dda221f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#方法二\n",
    "title.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a4164a10",
   "metadata": {},
   "source": [
    "### page59 in 检查成员对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d8c70e30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in title\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93e9d51a",
   "metadata": {},
   "source": [
    "## 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3fbe34ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" + \",\"+ \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "7b22ccf9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "acab\n"
     ]
    }
   ],
   "source": [
    "print(\"a\"+\"c\"+\"a\"+\"b\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "d92d4af1",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [31]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m你好\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2\u001b[39;49m)\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "print(\"你好\"+ 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "c075b27a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好5\n"
     ]
    }
   ],
   "source": [
    "# 但是字符串里的数字可以   \"5\"这样也是属于字符串\n",
    "print(\"你好\"+\"5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "f327027e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "484921cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7e24c161",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [35]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以用来运算\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 字符串不可以用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c8c84c14",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串和数字导致的笑话\n",
    "width=\"10\"\n",
    "heigt=8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "3b62cb91",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积=width * heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "84112bd2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1010101010101010'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3baa3925",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 正确做法\n",
    "width = 10\n",
    "heigt = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "189115c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "59b67c71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "80"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e92f393",
   "metadata": {},
   "source": [
    "## 字符串的方法\n",
    "> 1. str.capitalize():可以将字母转成大写\n",
    "> 2. str.count():数量\n",
    "> 3. str.split()：去除内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "30d68e93",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "068d024d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "79c693b4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "1a335b03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化区温泉镇'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "42e101ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "2be01c83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化区温泉镇']"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2d144ae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
